package com.sugar.follow.up.module.business.controller.app.publicityeducation;

import com.sugar.follow.up.framework.common.pojo.CommonResult;
import com.sugar.follow.up.framework.common.pojo.PageResult;
import com.sugar.follow.up.framework.common.util.object.BeanUtils;
import com.sugar.follow.up.module.business.controller.admin.publicityeducation.vo.PublicityEducationPageReqVO;
import com.sugar.follow.up.module.business.controller.app.publicityeducation.vo.AppPublicityEducationDetailRespVO;
import com.sugar.follow.up.module.business.controller.app.publicityeducation.vo.AppPublicityEducationSimpleRespVO;
import com.sugar.follow.up.module.business.dal.dataobject.publicityeducation.PublicityEducationDO;
import com.sugar.follow.up.module.business.service.publicityeducation.PublicityEducationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static com.sugar.follow.up.framework.common.pojo.CommonResult.successApp;

@Tag(name = "APP - 宣教")
@RestController
@RequestMapping("/biz/publicity-education")
@Validated
public class AppPublicityEducationController {

    @Resource
    private PublicityEducationService publicityEducationService;

    @GetMapping("/get")
    @Operation(summary = "获得宣教")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PermitAll
    public CommonResult<AppPublicityEducationDetailRespVO> getPublicityEducation(@RequestParam("id") Long id) {
        return successApp(publicityEducationService.appGetPublicityEducation(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得宣教分页")
    @PermitAll
    public CommonResult<PageResult<AppPublicityEducationSimpleRespVO>> getPublicityEducationPage(@Valid PublicityEducationPageReqVO pageReqVO) {
        PageResult<PublicityEducationDO> pageResult = publicityEducationService.getPublicityEducationPage(pageReqVO);
        return successApp(BeanUtils.toBean(pageResult, AppPublicityEducationSimpleRespVO.class));
    }
}